package com.xintai.sparepart.spareandpart.service.impl;

import java.util.Date;
import java.util.List;

import com.xintai.common.constant.Constants;
import com.xintai.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.xintai.sparepart.spareandpart.mapper.BeiCangkuMapper;
import com.xintai.sparepart.spareandpart.domain.BeiCangku;
import com.xintai.sparepart.spareandpart.service.IBeiCangkuService;

/**
 * 仓库Service业务层处理
 *
 * @author xintai
 * @date 2020-12-22
 */
@Service
public class BeiCangkuServiceImpl implements IBeiCangkuService
{
    @Autowired
    private BeiCangkuMapper beiCangkuMapper;

    private static Integer cangkuNumber = 1;

    /**
     * 查询仓库
     *
     * @param cangkuId 仓库ID
     * @return 仓库
     */
    @Override
    public BeiCangku selectBeiCangkuById(Long cangkuId)
    {
        return beiCangkuMapper.selectBeiCangkuById(cangkuId);
    }

    /**
     * 查询仓库列表
     *
     * @param beiCangku 仓库
     * @return 仓库
     */
    @Override
    public List<BeiCangku> selectBeiCangkuList(BeiCangku beiCangku)
    {
        return beiCangkuMapper.selectBeiCangkuList(beiCangku);
    }

    /**
     * 新增仓库
     *
     * @param beiCangku 仓库
     * @return 结果
     */
    @Override
    public int insertBeiCangku(BeiCangku beiCangku)
    {
        beiCangku.setCangkuUid(SecurityUtils.getLoginUser().getUser().getUserId());
        beiCangku.setCangkuTime(new Date());
        return beiCangkuMapper.insertBeiCangku(beiCangku);
    }

    /**
     * 修改仓库
     *
     * @param beiCangku 仓库
     * @return 结果
     */
    @Override
    public int updateBeiCangku(BeiCangku beiCangku)
    {
        return beiCangkuMapper.updateBeiCangku(beiCangku);
    }

    /**
     * 批量删除仓库
     *
     * @param cangkuIds 需要删除的仓库ID
     * @return 结果
     */
    @Override
    public int deleteBeiCangkuByIds(Long[] cangkuIds)
    {
        return beiCangkuMapper.deleteBeiCangkuByIds(cangkuIds,Constants.FAIL);
    }

    /**
     * 删除仓库信息
     *
     * @param cangkuId 仓库ID
     * @return 结果
     */
    @Override
    public int deleteBeiCangkuById(Long cangkuId)
    {
        return beiCangkuMapper.deleteBeiCangkuById(cangkuId, Constants.FAIL);
    }

    /**
     * 查重名
     * @param cangkuName
     * @return
     */
    @Override
    public boolean selectNamesake(String cangkuName) {
        if(cangkuNumber.equals(beiCangkuMapper.selectcangkuNamesake(cangkuName))){
            return true;
        }
        return false;
    }

    @Override
    public boolean selectkuwei(Long cangkuId) {
        if (beiCangkuMapper.selectkuwei(cangkuId)>0){
            return true;
        }
        return false;
    }
}
